package mySocketTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class SendDemo {
    public static void main(String[] args) throws IOException {
        // 创建发送端Socket对象
        DatagramSocket ds = new DatagramSocket();

        // 封装键盘录入对象
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while((line = in.readLine()) != null){
            if(line.equals("886")){
                break;
            } else {
                byte[] bys = line.getBytes();
                DatagramPacket dp = new DatagramPacket(bys, bys.length,
                        InetAddress.getByName("172.19.17.207"), 11111);
                ds.send(dp); // 发送数据包
            }
        }
        byte[] bys = "886".getBytes();
        DatagramPacket dp = new DatagramPacket(bys, bys.length,
                InetAddress.getByName("172.19.17.207"), 11111);
        ds.send(dp); // 发送数据包
        ds.close();
    }
}
